package com.aurora.source.authority.activity;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v7.widget.AppCompatButton;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.View;

import com.aurora.source.R;
import com.aurora.source.authority.adapter.ProcessAuthSelectAdapter;
import com.aurora.source.authority.adapter.AuthTypeAdapter;
import com.aurora.source.authority.adapter.SelectedAuthAdapter;
import com.aurora.source.authority.bean.AuthDataBean;
import com.aurora.source.authority.bean.AuthTypeDataBean;
import com.aurora.source.base.BasePresenter;
import com.aurora.source.base.BaseRecyclerAdapter;
import com.aurora.source.base.BaseWhiteToolbarActivity;
import com.aurora.source.util.DpPxUtil;
import com.aurora.source.widget.flowlayout.FlowLayoutManager;
import com.aurora.source.widget.flowlayout.SpaceItemDecoration;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * @author: ww
 * @description:权限选择
 * @date: 2018/9/10
 */
public class SelectAuthActivity extends BaseWhiteToolbarActivity {
    @BindView(R.id.rv_selected_auth)
    RecyclerView rvSelectedAuth;
    @BindView(R.id.rv_auth_type)
    RecyclerView rvAuthType;
    @BindView(R.id.rv_auth_data)
    RecyclerView rvAuthData;
    @BindView(R.id.button)
    AppCompatButton button;

    SelectedAuthAdapter selectedAuthAdapter; //已选择的权限
    AuthTypeAdapter authTypeAdapter; //权限分类
    ProcessAuthSelectAdapter processAuthSelectAdapter; // 权限选择

    List<AuthDataBean> selectedAuthData = new ArrayList<>(); //选择的数据
    List<AuthTypeDataBean> authTypeDataBeans = new ArrayList<>(); //所有分类数据


    @Override
    public BasePresenter attach() {
        return null;
    }

    @Override
    public int bindLayout() {
        return R.layout.activity_select_auth;
    }

    @Override
    public void initData(@Nullable Bundle bundle) {

        //六个分类数据
        for(int i=0;i<6;i++){
            AuthTypeDataBean typeDataBean = new AuthTypeDataBean();
            //分类下面的数据
            List<AuthDataBean> datas = new ArrayList<>();
            for(int j=0;j<5;j++){
                datas.add(new AuthDataBean());
            }
            typeDataBean.setAuthDataBeanList(datas);
            authTypeDataBeans.add(typeDataBean);
        }

    }

    @Override
    public void initView(Bundle savedInstanceState, View contentView) {

        simpleToolbar.setMainTitle("权限管理-添加授权");
        simpleToolbar.setLeftVisibility(View.VISIBLE);

        selectedAuthAdapter = new SelectedAuthAdapter();
        authTypeAdapter = new AuthTypeAdapter();
        processAuthSelectAdapter = new ProcessAuthSelectAdapter();

        //已经选择的权限数据
        selectedAuthAdapter.setDataList(selectedAuthData);
        selectedAuthAdapter.setOnItemClickListener(new BaseRecyclerAdapter.OnItemClickListener<AuthDataBean>() {
            @Override
            public void onClick(int position, AuthDataBean data) {
                processAuthSelectAdapter.notifyDataSetChanged();
            }
        });
        //分类数据
        authTypeAdapter.setDataList(authTypeDataBeans);
      /*  authTypeAdapter.setOnItemClickListener(new BaseRecyclerAdapter.OnItemClickListener<AuthTypeDataBean>() {
            @Override
            public void onClick(int position, AuthTypeDataBean data) {
                processAuthSelectAdapter.setDataList(data.getAuthDataBeanList());
            }
        });
        //选择数据
        processAuthSelectAdapter.setOnItemClickListener(new BaseRecyclerAdapter.OnItemClickListener<AuthDataBean>() {
            @Override
            public void onClick(int position, AuthDataBean data) {
                if(data.isSelected()){ //选中
                    selectedAuthAdapter.addItem(data);
                }else{
                    selectedAuthAdapter.deletItem(data);
                }
            }
        });
*/


        rvSelectedAuth.setAdapter(selectedAuthAdapter);
        rvSelectedAuth.setLayoutManager(new FlowLayoutManager());




        rvAuthType.setLayoutManager(new LinearLayoutManager(this));
        rvAuthType.setAdapter(authTypeAdapter);


        rvAuthData.setLayoutManager(new FlowLayoutManager());
        rvAuthData.setAdapter(processAuthSelectAdapter);
        rvAuthData.addItemDecoration(new SpaceItemDecoration(DpPxUtil.dp2px(this,5)));

    }

    @Override
    public void doBusiness() {

    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        // TODO: add setContentView(...) invocation
        ButterKnife.bind(this);
    }
}
